/**
 * 单桌结果页面
 * by wyy
 */
class resultScene extends GameObject implements eui.UIComponent {
    public windowGrp: eui.Group;
    public titleLbl: eui.Label;
    public nameLbl0: eui.Label;
    public nameLbl1: eui.Label;
    public nameLbl2: eui.Label;
    public nameLbl3: eui.Label;
    public nameLbl4: eui.Label;
    public nameLbl5: eui.Label;
    public nameLbl6: eui.Label;
    public nameLbl7: eui.Label;
    public nameLbl8: eui.Label;
    public nameLbl9: eui.Label;
    public nameLbl10: eui.Label;
    public scoreLbl0: eui.Label;
    public scoreLbl1: eui.Label;
    public scoreLbl2: eui.Label;
    public scoreLbl3: eui.Label;
    public scoreLbl4: eui.Label;
    public scoreLbl5: eui.Label;
    public scoreLbl6: eui.Label;
    public scoreLbl7: eui.Label;
    public scoreLbl8: eui.Label;
    public scoreLbl9: eui.Label;
    public scoreLbl10: eui.Label;
    public resultLbl0: eui.Label;
    public resultLbl1: eui.Label;
    public resultLbl2: eui.Label;
    public resultLbl3: eui.Label;
    public resultLbl4: eui.Label;
    public resultLbl5: eui.Label;
    public resultLbl6: eui.Label;
    public resultLbl7: eui.Label;
    public resultLbl8: eui.Label;
    public resultLbl9: eui.Label;
    public resultLbl10: eui.Label;
    public timeLbl0: eui.Label;
    public timeLbl1: eui.Label;
    public timeLbl2: eui.Label;
    public timeLbl3: eui.Label;
    public timeLbl4: eui.Label;
    public timeLbl5: eui.Label;
    public timeLbl6: eui.Label;
    public timeLbl7: eui.Label;
    public timeLbl8: eui.Label;
    public timeLbl9: eui.Label;
    public timeLbl10: eui.Label;
    public closeBtn: eui.Button;
    public rewardImg: eui.Image;

    public rankLbl0: eui.Label;
    public rankLbl1: eui.Label;
    public rankLbl2: eui.Label;

    public btnGrp: eui.Group;
    public refreshBtn: eui.Button;
    public nameLbl: eui.Label;

    heightPercent = 1;
    widthPercent = 1;

    type = "result";

    private data;
    private round;
    private no;

    constructor(d, round, no) {
        super();
        this.skinName = "resource/eui_skins/game_skins/resultSceneSkin.exml";
        this.data = d;
        this.round = round;
        this.no = no;
    }
    addToStage() { }
    firstCreate() {
        this.nameLbl.text = globalObject.getInstance().player.Username;

        this.closeBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.close, this);
        this.titleLbl.text = `第${this.round}轮第${this.no}桌博饼结果`;
        this.rewardImg = new eui.Image(`reward${(4 - this.round)}_png`);
        this.addChild(this.rewardImg);
        this.refresh();
        this.refreshBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.refresh, this);
    }
    private refresh() {
        nano.request("gamemanager.getsomedeskrank", { round: this.round, desk_num: this.no }, (d) => {
            globalObject.getInstance().debugConsole(`第${this.round}轮 第${this.no}桌 桌子信息`, d);
            this.data = d;
            for (let i = 0; i < 11; i++) {
                let rank = "rankLbl" + i;
                let name = "nameLbl" + i;
                let score = "scoreLbl" + i;
                let result = "resultLbl" + i;
                let time = "timeLbl" + i;
                if (this.data.Ranks[i]) {
                    this[name].text = this.data.Ranks[i]["name"];
                    if (this.data.Ranks[i]["total"] == 0) {
                        (<eui.Label>this[name]).bold = false;
                        (<eui.Label>this[name]).textColor = 0x9f5c33;
                        (<eui.Label>this[score]).bold = false;
                        (<eui.Label>this[score]).textColor = 0x9f5c33;
                        (<eui.Label>this[result]).bold = false;
                        (<eui.Label>this[result]).textColor = 0x9f5c33;
                        (<eui.Label>this[time]).bold = false;
                        (<eui.Label>this[time]).textColor = 0x9f5c33;
                        if (this[rank]) {
                            (<eui.Label>this[rank]).bold = false;
                            (<eui.Label>this[rank]).textColor = 0x9f5c33;
                        }

                    }
                    this[score].text = this.data.Ranks[i]["total"];
                    (<eui.Label>this[score]).textAlign = "center";
                    if (this.data.Ranks[i]["result"] == "") {
                        this[result].text = "0,0,0,0";
                    }
                    else {
                        this[result].text = globalObject.getInstance().resultSort(this.data.Ranks[i]["result"]);
                        globalObject.getInstance().resultSort(this.data.Ranks[i]["result"]);
                    }
                    let timeS = globalObject.getInstance().timestampToTimeString(this.data.Ranks[i]["roll_time"]);
                    this[time].text = timeS;
                }
                else {
                    this[rank].visible = false;
                    this[name].visible = false;
                    this[score].visible = false;
                    this[result].visible = false;
                    this[time].visible = false;
                }
            }
            this.windowGrp.visible = true;
        });

    }
    onRemove() { }
    private close() {
        SceneManager.getInstance().closeWindow();
        SceneManager.getInstance().changeScene(new hallScene());
    }
    childrenResize() {
        this.childResize({ xPercent: 0.68, yPercent: 0.5, heightPercent: 0.7 }, this.windowGrp);
        this.childResize({ xPercent: 0.5, yPercent: 0.9, widthPercent: 0.14 }, this.btnGrp);
        this.childResize({ xPercent: 0.22, yPercent: 0.5, widthPercent: 0.35 }, this.rewardImg);
    }
}